import java.awt.Graphics;


/**
*	A class to represent an LED display.
*	It consists of 3 digits. 
*	Each digit has 7 components, which can either be on or off, creating
*	characters on the display.
*
*	The components are listed from left to right, top to bottom.
*
*	I.e.: 
*			-- 0 --
*			|     |
*			1	  2
*			|     |
*			-- 3 --
*			|     |
*			4	  5
*			|     |
*			-- 6 --

**/
public class LED 
{

	/**
	*	The display width, in pixels, of the entire LED array.
	**/
	public static final int PIXELS_WIDE = 11;
	
	/**
	*	The display height, in pixels, of the entire LED array.
	**/
	public static final int PIXELS_TALL = 21;


	/**
	*	The width of the tallest components, in pixels.
	**/
	public static final int PIXELS_COMPONENT_WIDE = 3;


	/**
	*	The amount the 'mid' component should move up by/
	**/
	public static final int PIXELS_COMPONENT_MID_OFFSET = 2;



	/**
	*	The component sequence to represent a ZERO digit.
	**/
	public static final boolean[] ZERO= {true,true,true,false,true,true,true};
	
	/**
	*	The component sequence to represent a ONE digit.
	**/
	public static final boolean[] ONE = {false,false,true,false,false,true,false};
	
	/**
	*	The component sequence to represent a TWO digit.
	**/
	public static final boolean[] TWO = {true,false,true,true,true,false,true};
	
	/**
	*	The component sequence to represent a THREE digit.
	**/
	public static final boolean[] THREE= {true,false,true,true,false,true,true};
	
	/**
	*	The component sequence to represent a FOUR digit.
	**/
	public static final boolean[] FOUR= {false,true,true,true,false,true,false};
	
	/**
	*	The component sequence to represent a FIVE digit.
	**/
	public static final boolean[] FIVE= {true,true,false,true,false,true,true};

	/**
	*	The component sequence to represent a SIX digit.
	**/
	public static final boolean[] SIX= {true,true,false,true,true,true,true};
	
	/**
	*	The component sequence to represent a SEVEN digit.
	**/
	public static final boolean[] SEVEN= {true,false,true,false,false,true,false};
	
	/**
	*	The component sequence to represent a EIGHT digit.
	**/
	public static final boolean[] EIGHT= {true,true,true,true,true,true,true};

	/**
	*	The component sequence to represent a NINE digit.
	**/
	public static final boolean[] NINE= {true,true,true,true,false,true,true};

	/**
	*	The component sequence to represent a NINE digit.
	**/
	public static final boolean[] MINUS= {false,false,false,true,false,false,false};



	private boolean value[];


	public LED()
	{

		setValue(0);

	}



	
	public void setValue(int val) throws IllegalArgumentException{

		switch (val)
		{
		case -1:
			value = MINUS;
			break;
		case 0:
			value = ZERO;
			break;
		case 1:
			value = ONE;
			break;
		case 2:
			value = TWO;
			break;
		case 3:
			value = THREE;
			break;
		case 4:
			value = FOUR;
			break;
		case 5:
			value = FIVE;
			break;
		case 6:
			value = SIX;
			break;
		case 7:
			value = SEVEN;
			break;
		case 8:
			value = EIGHT;
			break;
		case 9:
			value = NINE;
			break;

		default:
			throw new IllegalArgumentException(
					"Value must be between 0 and 9, or -1.(not "+val+").");

		}

	}


	/**
	* A function to display the LED to the given graphics context.
	**/

	public void displayLED(Graphics g,int x,int y)
	{

		if(value[0])
		{

			g.drawImage(Game.images[Game.IMG_LED_TOP_ON],x,y,null);

		}else
		{
			g.drawImage(Game.images[Game.IMG_LED_TOP_OFF],x,y,null);


		}

		if(value[1])
		{

			g.drawImage(Game.images[Game.IMG_LED_LEFT_ON],x,y,null);

		}else
		{
			g.drawImage(Game.images[Game.IMG_LED_LEFT_OFF],x,y,null);


		}

		if(value[2])
		{

			g.drawImage(Game.images[Game.IMG_LED_RIGHT_ON],x + PIXELS_WIDE -
				  PIXELS_COMPONENT_WIDE,y,null);

		}else
		{

			g.drawImage(Game.images[Game.IMG_LED_RIGHT_OFF],x + PIXELS_WIDE -
				  PIXELS_COMPONENT_WIDE,y,null);

		}

		if(value[3])
		{

			g.drawImage(Game.images[Game.IMG_LED_MID_ON],x,
						y + PIXELS_WIDE -PIXELS_COMPONENT_MID_OFFSET ,null);

		}else
		{

			g.drawImage(Game.images[Game.IMG_LED_MID_OFF],x,
						y + PIXELS_WIDE -PIXELS_COMPONENT_MID_OFFSET ,null);

		}

		if(value[4])
		{

			g.drawImage(Game.images[Game.IMG_LED_LEFT_ON],x,
						y + PIXELS_WIDE ,null);

		}else
		{

			g.drawImage(Game.images[Game.IMG_LED_LEFT_OFF],x,
						y + PIXELS_WIDE,null);

		}
		if(value[5])
		{

			g.drawImage(Game.images[Game.IMG_LED_RIGHT_ON],x + PIXELS_WIDE -
				  PIXELS_COMPONENT_WIDE,
						y + PIXELS_WIDE ,null);

		}else
		{

			g.drawImage(Game.images[Game.IMG_LED_RIGHT_OFF],x + PIXELS_WIDE -
				  PIXELS_COMPONENT_WIDE,
						y + PIXELS_WIDE ,null);

		}
		if(value[6])
		{

			g.drawImage(Game.images[Game.IMG_LED_BOTTOM_ON],x,
					y + (PIXELS_WIDE * 2) - (PIXELS_COMPONENT_WIDE ) ,null);

		}else
		{

			g.drawImage(Game.images[Game.IMG_LED_BOTTOM_OFF],x,
					y + (PIXELS_WIDE * 2) - (PIXELS_COMPONENT_WIDE ) ,null);

		}


	}



}
